<template>
	<view class="enter-phone">
		<view class="enter-phone-close"><image src="https://master.shengejiaju.cn/web/static/icons/ico_close@2x.png" mode="aspectFit" @click="goback"></image></view>
		<view class="enter-phone-tit">
			<text>您好！</text>
			<text>欢迎来到深哥家具</text>
		</view>
		<view class="enter-phone-input"><input type="digit" placeholder-style="color: #C9C9C9" placeholder="您的手机号码" v-model="phone" maxlength="11"></view>
		<view class="enter-phone-btn">
			<button type="primary" :class="phone.length==11&&agree?'active':''" :disabled="phone.length==11?false:true" @click="getCode">获取验证码</button>
		</view>		
	</view>
</template>

<script>
	export default{
		data(){
			return {
				phone: '',
				agree: true
			}
		},
		methods: {
			goback(){
				uni.navigateBack()
			},
			getCode(){
				let phoneRexp = /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[0-9])\d{8}$/;
				if(!phoneRexp.test(this.phone)){
					uni.showToast({
						icon: 'none',
						title: '请输入正确的手机号码'
					})
					return false
				}
				let data = {
					phone: this.phone,
					login_code: 'login'
				}
				this.$api.PhoneGetCode(data).then(res => {
					uni.showToast({
						icon: 'none',
						title: '发送成功',
						duration: 1500
					})
					setTimeout(() => {
						uni.navigateTo({
							url: '/pages/login/login-2?phone='+this.phone
						})
					},1500)
				})
			},
			close(type){
				switch (Number(type)){
					case 1:
						this.$refs.protocol.close()
						break;
					case 2:
						this.$refs.privacy.close()
						break;
				}
			}
		}
	}
</script>

<style lang="scss">
	@import '../../static/scss/login.scss'
</style>